<?php

namespace app\modules\Product\controllers;

use Yii;
use app\modules\Product\models\ProductTour;
use app\modules\Product\models\ProductTourSearch;
use app\modules\Product\models\Product;
use app\modules\Product\models\ProductSearch;

use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * 团队导游设置
 */
class TourController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    //团队列表
    public function actionIndex($product_id)
    {
        $searchModel = new ProductTourSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams,$product_id);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'product_id' => $product_id,
        ]);
    }

    //查看详情
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    //创建
    public function actionCreate($product_id)
    {
        $model = new ProductTour();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }else{
            
            $model->product_id = $product_id;

            return $this->render('create', [
                'model' => $model,
            ]);
        }

        
    }

    //更新
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }

        return $this->render('update', [
            'model' => $model,
        ]);
    }

   
    
    protected function findModel($id)
    {
        if (($model = ProductTour::findOne($id)) !== null) {
            return $model;
        }

        throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
    }
}
